﻿using KZ.Express.ENT;
using KZ.Express.Presenter;
using KZ.Utilities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KZ.Express
{
    public partial class LoginView : FormBase
    {
        new LoginPresenter _presenter;

        public LoginView()
        {
            InitializeComponent();
            this.TopLevel = true;
            _presenter = new LoginPresenter(this);
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                UserENT user = _presenter.Login(txtUsername.Text, txtPassword.Text);
                UserENT.USERID = user.UserID;
                UserENT.ROLEID = user.RoleID.Value;

                this.DialogResult = DialogResult.OK;
            }
            catch (BusinessLogicException ex)
            {
                SetMessage(ex.Message, false);
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
